#ifndef _MISC_SAMPLE_DEV_H
#define _MISC_SAMPLE_DEV_H 1

#include <linux/types.h>
// #include <net/sock.h>
// #include <linux/in.h>

// 动作
#define NF_POLICY_ACTION_DROP 0
#define NF_POLICY_ACTION_ACCEPT 1
// 方向
#define NF_POLICY_DIR_IN 0
#define NF_POLICY_DIR_OUT 1
// 修改策略的操作类型
#define NF_CHANGE_POLICY_TYPE_REMOVE 0
#define NF_CHANGE_POLICY_TYPE_ADD 1

struct proc_info {
    unsigned int pid;
    char comm[16];
    // proc_info() {
    //     pid = 0;
    //     memset(comm, 0, sizeof(comm));
    // };
};

union inet_addr {
    __u32 all[4];
    __be32 ip;
    __be32 ip6[4];
    // inet_addr() {
    //     memset(all, 0, sizeof(all));
    //     ip = 0;
    //     memset(ip6, 0, sizeof(ip6));
    // };
};

struct net_filter_policy {
    unsigned int np_id;
    char action;
    char dir;
    struct proc_info proc;
    int family;
    char match_all_protocol;
    int protocol;
    char match_all_src_ip;
    union inet_addr src_addr_begin;
    union inet_addr src_addr_end;
    char match_all_src_port;
    unsigned int src_port_begin;
    unsigned int src_port_end;
    char match_all_dst_ip;
    union inet_addr dst_addr_begin;
    union inet_addr dst_addr_end;
    char match_all_dst_port;
    unsigned int dst_port_begin;
    unsigned int dst_port_end;
    // net_filter_policy() {
    //     np_id = 0;
    //     action = NF_POLICY_ACTION_ACCEPT;
    //     dir = NF_POLICY_DIR_IN;
    //     family = AF_INET;
    //     match_all_protocol = true;
    //     protocol = IPPROTO_TCP;
    //     match_all_src_ip = true;
    // // union inet_addr src_addr_begin;
    // // union inet_addr src_addr_end;
    //     match_all_src_port = true;
    // src_port_begin = 1;
    // src_port_end = 65535;
    //     match_all_dst_ip = true;
    // // union inet_addr dst_addr_begin;
    // // union inet_addr dst_addr_end;
    //     match_all_dst_port = true;
    // dst_port_begin = 1;
    // dst_port_end = 65535;
    // };
};

struct net_filter_change_policy {
    char type;
    struct net_filter_policy policy;
    // net_filter_change_policy() {
    //     type = NF_CHANGE_POLICY_TYPE_ADD;
    // };
};

#endif